int speakerPin = 9;
int length = 592; // the number of notes
char notes[] = "EE E CE G   g   C  g  e  a b ha gEG A FG E CDb  C  g  e  a b ha gEG A FG E CDb    GYF4 E waC aCD  GYF4 E [ [[     GYF4 E waC aCD  4  D  C         GYF4 E waC aCD  GYF4 E [ [[     GYF4 E waC aCD  4  D  C       CC C CD EC ag   CC C CDE        CC C CD EC ag   EE E CE G   g   C  g  e  a b ha gEG A FG E CDb  C  g  e  a b ha gEG A FG E CDb  EC g  w aF Fa   bA AAG FEC ag   EC g  w aF Fa   bF FFE DCe ec   EC g  w aF Fa   bA AAG FEC ag   EC g  w aF Fa   bF FFE DCe ec   CC C CD EC ag   CC C CDE        CC C CD EC ag   EE E CE G   g   EC g  w aF Fa   bA AAG FEC ag   EC g  w aF Fa   bF FFE DCe ec   "; // a space represents a rest | an h represents a b flat | Y reps G flat
//char notes[] = "c d e f g w a h b C D 4 E F G A"; Musical Scale (of available note) ;)
void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}
void playNote(char note, int duration) {
  char names[] = { 
     'c', 'd', 'e', 'f', 'g', 'w'/*a flat*/,'a','h'/*b flat*/, 'b', 'C', 'D', '4'/*E flat*/, 'E', 'F', 'Y', 'G', 'A', 'B','['};
  int tones[] = { 
    1915, 1700, 1519, 1432, 1275, 1204, 1136, 1072, 1014, 956, 851, 803, 758, 716, 676, 638, 568, 506, 478};
  // play the tone corresponding to the note name
  for (int i = 0; i < 20; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}
void setup() {
  pinMode(speakerPin, OUTPUT);
}

void loop() {
  for (int i = 0; i <= length; i++) {
    if (notes[i] == ' ') {
      delay(100); // rest
    } 
    else {
      playNote(notes[i], 100);
    }
    // pause between notes
    delay(100 / 2); 
  }
}
